/*
 * SRM 148 Div 1 Prob 2
 */

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;


public class MNS
{
    int ans = 0;
    
    public boolean checkPermution (int[] numbers) {
	int[][] check = new int[3][3];
	for (int i = 0; i < 3; ++i)
	    for (int j = 0; j < 3; ++j)
		check[i][j] = numbers[3*i+j];
	int sum = check[0][0] + check[0][1] + check[0][2];
	for (int i = 0; i <= 2; ++i) {
	    if (check[i][0] + check[i][1] + check[i][2] != sum)
		return false;
	    if (check[0][i] + check[1][i] + check[2][i] != sum)
		return false;
	}
	return true;
    }
    
    void go (int k, int[] index, int[] left, int[] num) {
	if (k == 9) {
	    if (checkPermution (num))
		++ans;
	    return;
	}
	for (int i = 0; i < index.length; ++i) {
	    if (left[i] > 0) {
		left[i]--;
		num[k] = index[i];
		go (k+1, index, left, num);
		++left[i];
	    }
	}
    }

    public int combos(int[] numbers)
    {
	HashMap<Integer, Integer> hm = new HashMap<Integer, Integer> ();
	for (int o:numbers) {
	    if (hm.containsKey (o))
		hm.put (o, hm.get (o)+1);
	    else
		hm.put (o, 1);
	}
	int len = hm.size ();
	int i = 0;
	int[] index = new int[len], left = new int[len];
	for (int o:hm.keySet ()) {
	    index[i] = o;
	    left[i++] = hm.get (o);
	}
	int[] num = new int[9];
	ans = 0;
	go (0, index, left, num);
	return ans;
    }
    

}
//Powered by KawigiEdit 2.1.4 (beta) modified by pivanof!